package com.tuocent.dagv2.controller;

import com.alibaba.fastjson.JSONObject;
import com.tuocent.dagv2.common.AjaxResult;
import com.tuocent.dagv2.entity.Users;
import com.tuocent.dagv2.service.IExamineLogService;
import com.tuocent.dagv2.service.IUsersService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.Map;

@Controller
@RequestMapping("/system")
public class SystemController {
    @Autowired
    private IUsersService usersService;
    @Autowired
    private IExamineLogService examineLogService;

    @GetMapping("userInfo")
    public String userInfo(Model model) {
        return usersService.userInfo(model);
    }

    @PostMapping("getUserData")
    @ResponseBody
    public AjaxResult getUserData(@RequestBody Map<String, Object> param) {
        return usersService.getUserData(param);
    }

    @GetMapping("setUserInfo")
    public String setUserInfo(Model model,
                              @RequestParam(value = "id", defaultValue = "") String id) {
        return usersService.setUserInfo(model, id);
    }

    @PostMapping("saveUserInfo")
    @ResponseBody
    public AjaxResult saveUserInfo(HttpSession session, @RequestBody Users data) throws IOException {
        return usersService.saveUserInfo(session, data);
    }

    /**
     * 删除用户信息
     *
     */
    @RequestMapping("delUserInfo")
    @ResponseBody
    public AjaxResult delUserInfo(HttpSession session, @RequestParam(value = "id") String id) {
        return usersService.delUserInfo(session, id);
    }

    /**
     * 激活/禁用用户
     *
     */
    @RequestMapping("setUserEnabled")
    @ResponseBody
    public AjaxResult setUserEnabled(HttpSession session,
                                     @RequestBody Map<String, Object> params) {
        return usersService.setUserEnabled(session, params);
    }

    /**
     * 充值密码
     *
     * @param session
     * @param params
     * @return
     */
    @RequestMapping("resetPassword")
    @ResponseBody
    public AjaxResult resetPassword(HttpSession session, @RequestBody Map<String, Object> params) {
        return usersService.resetPassword(session, params);
    }

    /**
     * 设置用户任务
     *
     * @param model
     * @param userId
     * @return
     */
    @GetMapping("setUserRole")
    public String setUserRole(Model model,
                              @RequestParam("userId") String userId) {
        return usersService.setUserRole(model, userId);
    }

    @RequestMapping("getUserRole")
    @ResponseBody
    public AjaxResult getUserRole(HttpSession session, @RequestParam("userId") String userId) {
        return usersService.getUserRole(session, userId);
    }

    @RequestMapping("saveUserRole")
    @ResponseBody
    public AjaxResult saveUserRole(HttpSession session, @RequestBody JSONObject params) {
        return usersService.saveUserRole(session, params);
    }

    @GetMapping("logExamine")
    public String logExamine(Model model) {
        return examineLogService.logExamine(model);
    }

    @PostMapping("getExamineLog")
    @ResponseBody
    public AjaxResult getExamineLog(HttpSession session, @RequestBody Map<String, Object> params) {
        return examineLogService.getExamineLog(session, params);
    }

    @GetMapping("securityExamine")
    public String securityExamine(Model model) {
        return examineLogService.securityExamine(model);
    }
}
